/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Ventana4.java
 *
 * Created on 07-may-2012, 13:33:51
 */
package gui;

import controles.ControlCreacion;
import src.Core;

/**
 *
 * @author usuario_local
 */
public class Ventana4 extends javax.swing.JFrame {
    
    private int padre;
    Ventana1 v1;
    Ventana3 v3;
    VentanaPersonaje vp;
    VentanaCargo vca;
    VentanaColectivo vco;
    VentanaAcontecimiento vac;

    public void setVac(VentanaAcontecimiento vac) {
        this.vac = vac;
    }

    public void setVco(VentanaColectivo vco) {
        this.vco = vco;
    }

    public void setVca(VentanaCargo vca) {
        this.vca = vca;
    }
    
    /** Creates new form Ventana4 */
    public Ventana4(Ventana1 v1,Ventana3 v3) {
        this.v1 = v1;
        this.v3 = v3;
        initComponents();
    }

    public void setPadre(int padre){
        this.padre = padre;
    }
    
    public void setPersonaje(VentanaPersonaje vp){
        this.vp = vp;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton_v4nuevo = new javax.swing.JButton();
        jButton_v4anadir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Elejir");
        setName("Elejir"); // NOI18N
        setResizable(false);

        jButton_v4nuevo.setText("Nuevo");
        jButton_v4nuevo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_v4nuevoMouseClicked(evt);
            }
        });

        jButton_v4anadir.setText("Añadir");
        jButton_v4anadir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_v4anadirMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton_v4nuevo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton_v4anadir)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton_v4nuevo)
                    .addComponent(jButton_v4anadir))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton_v4nuevoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_v4nuevoMouseClicked
        // TODO add your handling code here:
        switch(padre){
            case 1:
                vp = new VentanaPersonaje(v1,v3,this);
                vp.setVisible(true);
                this.setVisible(false);
                this.dispose();
                break;
            case 2:
                VentanaColectivo vco2 = new VentanaColectivo(v1,v3);
                vco2.setVisible(true);
                this.setVisible(false);
                this.dispose();
                break;
            case 3:
                VentanaAcontecimiento vac2 = new VentanaAcontecimiento(v1,v3);
                vac2.setVisible(true);
                this.setVisible(false);
                this.dispose();
                break;
            case 4:
                VentanaTiempo vt = new VentanaTiempo(1,v1,v3,vp);
                vt.setVisible(true);
                this.setVisible(false);
                this.dispose();
                break;
            case 5:
                VentanaFichero vf = new VentanaFichero(v1,v3,vca);
                vf.setVisible(true);
                vf.setPadre(1);
                this.setVisible(false);
                this.dispose();
                break;
            case 6:
                VentanaFichero vf2 = new VentanaFichero(v1,v3,vco);
                vf2.setVisible(true);
                vf2.setPadre(2);
                this.setVisible(false);
                this.dispose();
                break;
            case 7:
                VentanaFichero vf3 = new VentanaFichero(v1,v3,vac);
                vf3.setVisible(true);
                vf3.setPadre(3);
                this.setVisible(false);
                this.dispose();
                break;
        }
    }//GEN-LAST:event_jButton_v4nuevoMouseClicked

    private void jButton_v4anadirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_v4anadirMouseClicked
        // TODO add your handling code here:
        switch(padre){
            case 4:
                VentanaTiempo vt2 = new VentanaTiempo(2,v1,v3,vp);
                vt2.setVisible(true);
                this.setVisible(false);
                this.dispose();
                break;
            case 5:
                VentanaAnadir van2 = new VentanaAnadir(padre,v1,v3,vca);
                van2.setTexto(Core.dameTodosFicheros());
                if("".equals(van2.getTexto())){
                    vca.setVisible(true);
                }else {
                    van2.setVisible(true);
                }
                this.setVisible(false);
                this.dispose();
                break;
            case 6:
                VentanaAnadir van3 = new VentanaAnadir(padre,v1,v3,vco);
                van3.setTexto(Core.dameTodosFicheros());
                 if("".equals(van3.getTexto())){
                    vco.setVisible(true);
                }else {
                    van3.setVisible(true);
                }
                this.setVisible(false);
                this.dispose();
                break;
            case 7:
                VentanaAnadir van4 = new VentanaAnadir(padre,v1,v3,vac);
                van4.setTexto(Core.dameTodosFicheros());
                if("".equals(van4.getTexto())){
                    vac.setVisible(true);
                }else {
                    van4.setVisible(true);
                }
                this.setVisible(false);
                this.dispose();
                break;
            default:
                VentanaAnadir van5 = new VentanaAnadir(padre,v1,v3);
                    if(ControlCreacion.creando == ControlCreacion.Creacion.acontecimiento)
                    {
                        van5.setTexto(Core.dameTodosAcontecimientos());
                    } else if(ControlCreacion.creando == ControlCreacion.Creacion.colectivo)
                    {
                        van5.setTexto(Core.dameTodosColectivos());
                    } else if(ControlCreacion.creando == ControlCreacion.Creacion.personaje)
                    {
                        van5.setTexto(Core.dameTodosPersonajes());
                    }
                    if(!"".equals(van5.getTexto())){
                        van5.setVisible(true);
                    }else {
                        v3.setVisible(true);
                    }
                this.setVisible(false);
                this.dispose();
                break;
        }
    }//GEN-LAST:event_jButton_v4anadirMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton_v4anadir;
    private javax.swing.JButton jButton_v4nuevo;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
